package io.renren.modules.sys.controller;

import java.util.Arrays;
import java.util.Map;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.sys.entity.DictItemEntity;
import io.renren.modules.sys.service.DictItemService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;


/**
 * @author Amadeus
 * @email 313300182@qq.com
 * @date 2020-12-11 16:12:32
 */
@RestController
@RequestMapping("sys/dictitem")
@Api(tags = "字典列表")
public class DictItemController {
    @Autowired
    private DictItemService dictItemService;

    /**
     * 列表
     */
    @ApiOperation(value = "字典item表list", response = DictItemEntity.class)
    @RequestMapping("/list")
    public R list(@RequestParam Map<String, Object> params) {
        PageUtils page = dictItemService.getDictItemList(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") String id) {
        DictItemEntity dictItem = dictItemService.getById(id);

        return R.ok().put("dictItem", dictItem);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    public R save(@RequestBody DictItemEntity dictItem) {
        dictItemService.saveDictItem(dictItem);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody DictItemEntity dictItem) {
        dictItemService.saveOrUpdateDictItem(dictItem);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody String[] ids) {
        dictItemService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }

}
